﻿<html>
<head>
		<meta charset="UTF-8">
		<title>TextFlex - Home</title>
		<link type="text/css" rel="stylesheet" href="./styles/main.css">
		<link type="text/css" href="scripts/css/redmond/jquery-ui-1.8.18.custom.css" rel="Stylesheet" />	
		<script type="text/javascript" src="scripts/js/jquery-1.7.1.min.js"></script>
		<script type="text/javascript" src="scripts/js/jquery-ui-1.8.18.custom.min.js"></script>
		<script type="text/javascript" src="scripts/scripts.js"></script>
		
		<script type="text/javascript">

		function Testchamps(email, pwd)
		{
			var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');

			if(!reg.test(email))
			{
				$('#email').focus();
				error("Email incorrect !");
			}
			else if (pwd.length < 6)
			{
				$('#pwd').focus();
				error("Mot de passe incorrect ! (6 charactères minimum)");
			}
			else
			{
				return true;
			}
			return false;
		}

		
		$(function() {
			$("#btnConnecter").click(function() {

				var email = $('#email').val();
				var pwd = $('#pwd').val();

				if ($('#RememberMe').attr('checked'))
				{
					createCookie('TextFlexEmail',email);
					createCookie('TextFlexPWD',pwd);
				}
				else
				{
						eraseCookie('TextFlexEmail');
						eraseCookie('TextFlexPWD');
				}
				
				if(Testchamps(email, pwd))
				{
				$.post( 'connect.php', { email : email, pwd: pwd },
				  function( data ) {
						if (data == '1')
						{
						  info('Connecté');
						  $(location).attr('href','./');
						}
						else if (data == '0')
						{
						  error('Email ou mot de passe incorrect');
						  $('#email').focus();
						}
						else
						{
							load(data);
						}
				  });
		
				}
			})
		});
		
		$(function() {
			$("#btnInscription").click(function() {
				if(Testchamps())
				{
				$.post( 'inscription.php', { email : email, pwd: pwd },
				  function( data ) {
						if (data == '1')
						{
						  info('Connecté');
						  $(location).attr('href','./');
						}
						else if (data == '0')
						{
						  error('Email ou mot de passe incorrect');
						  $('#email').focus();
						}
						else
						{
							error("Un erreur s'est produite. Veuillez réessayer. L'email existe peut-être déja.");
							//error(data);
						}
				  });
				}
			})
		});

		function pageChargee()
		{
			//$("#logDivInfo").hide();
			//$("#logDivError").hide();
			
			//on récupère les cookies
			var cEmail = readCookie('TextFlexEmail');
			var cPWD = readCookie('TextFlexPWD');
			if (cEmail)
			{
				$('#email').val(cEmail);
				$('#pwd').val(cPWD);
				$('#RememberMe').attr('checked', true);
				
			}
			else
			{
				$('#RememberMe').attr('checked', false);
				
			}
			
		}		
		</script> 
	</head>
	<body onload="pageChargee()">
	<div align="center">
		<div class="div_logo">
			
		<table>
			<tr>
				<td rowspan="2"><img src="img/logo.png" alt="logo" class="logoImg" /></td>
				<td><h1 class="logoTxt">TextFlex</h1></td>
			</tr>
			<tr>
				<td><h2 class="logoTxtSec">Envoyez vos SMS depuis le web !</h2></td>
			</tr>
		</table>
		</div>
	</div>
					<div class="loginForm">
						<input type="email" name="email" id="email" class="SMStxt SMSdest" placeholder="adresse email"><br/>
						<input type="password" name="pwd" id="pwd" class="SMStxt SMSdest" placeholder="mot de passe"><br/>
						<input type="checkbox" id="RememberMe" name="RememberMe" value="RememberMe" /> Se sourvenir de moi<br />
						<br/><br/>
						<a href="#" id="btnConnecter" class="buttonBleu" style="float:none;">Se connecter</a>
						<a href="#" id="btnInscription" class="buttonVert" style="float:none;">S'inscrire</a>
					</div>
					<br/><br/><br/>
					<div class="ui-state-highlight ui-corner-all" id="logDivInfo" style="margin-top: 20px; padding: 0 .7em; display:none;"> 
						<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
						<span id="logInfo"></span> </p>
					</div>
					<div class="ui-state-error ui-corner-all" id="logDivError" style="padding: 0 .7em; display:none;"> 
						<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span> 
						<span id="logError"></span> </p>
					</div>	
		</body>
	</html>